package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.Result;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

//查询前台讲师
@RestController
@RequestMapping("/eduservice/frontTeacher")
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;

    @Autowired
    private EduCourseService courseService;

    //分页查询
    @GetMapping("pageTeacherCondition/{page}/{limit}")
    public Result pageTeacherCondition(@PathVariable long page,@PathVariable long limit){
        Page<EduTeacher> teacherPage=new Page<>(page,limit);
        Map<String,Object> map=teacherService.selectTeacherCondition(teacherPage);
        return Result.ok().data(map);
    }
    //查询讲师的信息和所属讲师课程的信息
    @GetMapping("getTeacherInfo/{teacherId}")
    public Result getTeacherInfo(@PathVariable String teacherId){
        //根据讲师的id查询讲师
        EduTeacher eduTeacher = teacherService.getById(teacherId);
        //查询所属讲师的课程
        QueryWrapper<EduCourse> wrapper=new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);
        List<EduCourse> courseList = courseService.list(wrapper);
        return Result.ok().data("courseList",courseList).data("teacher",eduTeacher);
    }
}
